#ifndef PORTABLECOLLECTOR_H
#define PORTABLECOLLECTOR_H

#include <QWidget>
#include <QTimer>
#include <QVector>
#include <QCloseEvent>
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QThread>
#include <QProcess>
#include <QSettings>
#include <QThread>
#include "qcustomplot.h"
#include "databufthread.h"
#include "rcvdata.h"
#include "parsedatathread.h"
#include "savedatathread.h"
#include "digitkeyboard.h"
#include "displaythread.h"
#include "jlog.h"
#include "header.h"
#include <QMetaType>
#include <sys/stat.h>

namespace Ui {
class PortableCollector;
}

class PortableCollector : public QWidget
{
    Q_OBJECT

public:
    explicit PortableCollector(QWidget *parent = 0);
    ~PortableCollector();

signals:
    void NoiseTestCollect();
    void SendData(unsigned char *DataBuf);

private slots:
    void on_pushBtn_Coll_clicked();

    void on_pushBtn_Test_clicked();

    void on_pushBtn_AddTime_clicked();

    void on_pushBtn_SubTime_clicked();

    void on_pushBtn_AddVoltage_clicked();

    void on_pushBtn_SubVoltage_clicked();

    void on_radioBtn_SeriesColl_clicked();

    void on_radioBtn_TrigColl_clicked();

    void HideTipInfo();

    void closeEvent(QCloseEvent *e);

    void InitRcvDataRight();

    void DisplayNoiseValue(float *data);

    void SaveDataError(); // 保存数据失败提醒

    void TrigDataTip();   // 触发数据保存提示

    void FinishedTrigSave(); // 保存完成信号

    void ReceiveKeyWord(char Key);

    void on_comboBox_Freq_currentIndexChanged(const QString &arg1);

    void on_radioBtn_Sync_clicked();

    void CmdSockMessage();

    void CmdSockError(QAbstractSocket::SocketError err);

    void RcvDataConnectErr();

    void SampeleWave(QVector<double> *data, float *MaxValue);

    void on_radioBtn_SDCard_clicked();

private:
    Ui::PortableCollector *ui;

    // 变量
    QVector<QCustomPlot*> WaveChannels;
    QVector<double> xValue;
    JLog log;
    QTcpSocket *SockCmd;
    QTcpSocket *SockData;
    em9108_cmd cmdArray[10];
    bool IsSDCardCheck;
    bool IsSDCardEnable;

    QTimer *HideTipInfoTimer;
    DigitKeyBoard *DKeyBoard;
    RcvData *RcvThread;
    QThread JRcv;
    DataBufThread *BufThread;
    QThread JBuf;
    ParseDataThread *ParseThread;
    QThread JParse;
    SaveDataThread *SaveThread;
    QThread JSave;
    DisplayThread *Display;
    QThread JDisp;

    // 函数
    bool Init(); // 初始化函数
    bool InitCtrls(); // 初始化控件
    void InitCtrlsData(); //
    void InitNetwork();
    void InitThreads();
    void EnableChannelInfo(bool Flag);
    void TipInfo(QString Info);
    void ReadConfigFile(); // 保存数据时间，方便操作文件

    bool ReadZeroFullValue();
    bool SendCmd(int CmdId, unsigned int Value);
    unsigned int BuildCmd(int Id, unsigned int Value, char *Cmdbuf);
    void Em9108Setting();
    void Em9108Start();
    void Em9108Stop();
};

#endif // PORTABLECOLLECTOR_H
